| Total Complexity | 2 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 7 | |||
| 8 | @CommandHandler(CreateContactCommand) |
||
| 9 | export class CreateContactCommandHandler { |
||
| 10 | constructor( |
||
| 11 | @Inject('IContactRepository') |
||
| 12 | private readonly contactRepository: IContactRepository |
||
| 13 | ) {} |
||
| 14 | |||
| 15 | public async execute(command: CreateContactCommand): Promise<string> { |
||
| 16 | const { firstName, lastName, company, email, phoneNumber, notes } = command; |
||
| 17 | |||
| 18 | if (!firstName && !lastName && !company) { |
||
| 19 | throw new EmptyContactException(); |
||
| 20 | } |
||
| 21 | |||
| 22 | const contact = await this.contactRepository.save( |
||
| 23 | new Contact(firstName, lastName, company, email, phoneNumber, notes) |
||
| 24 | ); |
||
| 25 | |||
| 26 | return contact.getId(); |
||
| 27 | } |
||
| 29 |